package cs3343.project.family.testing;

import static org.junit.Assert.*;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;

import org.junit.Test;

import cs3343.project.family.*;
import cs3343.project.family.Character;
import cs3343.project.family.UI.EventCardFrame;
import cs3343.project.family.UI.GameFrame;

/**
 * The Class rollDice.
 */
public class rollDice {

	/**
	 * The Class StatisticsControllerStub.
	 */
	class StatisticsControllerStub extends StatisticsController{

		/**
		 * Instantiates a new statistics controller stub.
		 *
		 * @param gc the gc
		 */
		public StatisticsControllerStub(GameController gc) {
			super(gc);
			gc.setStatisticsController(this);
		}
		
		/* (non-Javadoc)
		 * @see cs3343.project.family.StatisticsController#addEsteemChange(int, int)
		 */
		@Override 
		public void addEsteemChange(int index, int esteem) {
			
		}
		
		/* (non-Javadoc)
		 * @see cs3343.project.family.StatisticsController#addplayerLog(int, java.lang.String)
		 */
		@Override 
		public void addplayerLog(int index, String event) {
		}
		
	};
	

	/* Case: Player's esteem is negative in value at first time
	 * Result: APlayer's esteem become 100 and wont end game 
	 */
	
	/**
	 * Lost game1.
	 */
	@Test
	public void lostGame1(){
		
		class CharacterStub extends Character{

			public CharacterStub(String name, char gender, ImageIcon image,
					ImageIcon gimage, ImageIcon icon) {
				super(name, image, gimage, icon);
			}
			public boolean getDiedOnce(){
				return false;
			}
		
		};
		
		GameController gc=new GameController();

		//player setting 
		String proimgPath = ConfigManager.IMAGE_PATH + "profilePic1" + ".jpg";
        String iconimgPath = ConfigManager.IMAGE_PATH + "char1" + ".jpg";
        String gproimgPath = ConfigManager.IMAGE_PATH + "gprofilePic1" + ".jpg";
        CharacterController cc=gc.getCharacterController();
        CharacterStub player = new CharacterStub("Player",'F', new ImageIcon(proimgPath),new ImageIcon(gproimgPath), new ImageIcon(iconimgPath));
        StatisticsControllerStub st=new StatisticsControllerStub(gc);
        gc.setStatisticsController(st);
        player.setEsteem(-100);
		cc.addPlayer(player, 0);
		gc.setIsStarted(true);
		boolean resultLost=gc.gameLost(0);
		int resultEsteem=cc.getPlayer(0).getEsteem();
		
		assertEquals(resultLost,false);
		assertEquals(resultEsteem,100);
	}
	
	/* Case: 2nd time for player to have a negative esteem
	 * Result: Game end
	 */
	/**
	 * Lost game2.
	 */
	@Test
	public void lostGame2(){
		class CharacterStub extends Character{

			public CharacterStub(String name, char gender, ImageIcon image,
					ImageIcon gimage, ImageIcon icon) {
				super(name, image, gimage, icon);
			}
			public boolean getDiedOnce(){
				return true;
			}
		
		};
		
		GameController gc=new GameController();
		StatisticsControllerStub st=new StatisticsControllerStub(gc);
        gc.setStatisticsController(st);
        
        //Player Setting
		String proimgPath = ConfigManager.IMAGE_PATH + "profilePic1" + ".jpg";
        String iconimgPath = ConfigManager.IMAGE_PATH + "char1" + ".jpg";
        String gproimgPath = ConfigManager.IMAGE_PATH + "gprofilePic1" + ".jpg";
        CharacterController cc=gc.getCharacterController();
        CharacterStub player = new CharacterStub("Player",'F', new ImageIcon(proimgPath),new ImageIcon(gproimgPath), new ImageIcon(iconimgPath));
		player.setEsteem(-150);
		cc.addPlayer(player, 0);
		gc.setCurrentPlayerIndex(0);
		
		boolean resultLost=gc.gameLost(0);

		assertEquals(resultLost,true);
	}
}
